package org.windowkit.toolkit.frame;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.plaf.metal.MetalBorders.InternalFrameBorder;


/**
 *
 * @author Rich O'Connell
 */
public class HighlightIFrameBorder extends InternalFrameBorder {
	private static final long serialVersionUID = 571539123638777396L;

	private final Color lightShade = new Color(229, 249, 255);
	private final Color midShade = new Color(204, 242, 255);
	private final Color darkUnselectedShade = new Color(153, 230, 255);
	private final Color darkSelectedShade = new Color(92, 205, 255);

	@Override
	public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) {
		super.paintBorder(c, g, x, y, w, h);

		if (c instanceof BaseIFrame) {
			BaseIFrame bif = (BaseIFrame) c;

			if (bif.isHighlight()) {

				g.setColor(lightShade);
				// Draw outermost lines
				g.drawLine(1, 0, w - 2, 0);
				g.drawLine(0, 1, 0, h - 2);
				g.drawLine(w - 1, 1, w - 1, h - 2);
				g.drawLine(1, h - 1, w - 2, h - 1);

				// Draw the bulk of the border
				g.setColor(midShade);
				g.drawRect(x + 1, y + 1, w - 3, h - 3);

				g.setColor(bif.isSelected() ? darkSelectedShade
						: darkUnselectedShade);
				for (int i = 2; i < 4; i++) {
					g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2) - 1);
				}
			}
		}

	}

}
